package com.eduadmin.controller;

import com.alibaba.excel.EasyExcel;
import com.eduadmin.entity.Semester;
import com.eduadmin.listener.SemesterDataUploadListener;
import com.eduadmin.service.ISemesterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Controller
public class SemesterController {
    //构造函数自动装配
    private final ISemesterService semesterService;

    @Autowired
    public SemesterController(ISemesterService semesterService) {
        this.semesterService = semesterService;
    }

    @RequestMapping(value = "addSemesters")
    @ResponseBody
    public String addSemesters(MultipartFile semesterFile) throws IOException {
        EasyExcel.read(semesterFile.getInputStream(), Semester.class, new SemesterDataUploadListener(semesterService)).sheet().doRead();
        return "上传成功";
    }
}